package com.tfswx.fljdmxyy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

/**
 * 任务定时器线程配置
 *
 * @Author 陈文佳
 * @Date 2023/3/16 16:07
 */
@EnableScheduling
@Configuration
public class SchedulingConfig {

    @Bean
    public TaskScheduler taskScheduler() {
        // 1.创建任务调度线程池
        ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
        // 2.初始化线程池数量
        taskScheduler.setPoolSize(5);
        // 3.是否将取消后的任务，从队列中删除
        taskScheduler.setRemoveOnCancelPolicy(true);
        // 4.设置线程名前缀
        taskScheduler.setThreadNamePrefix("TaskSchedulerThreadPool-");
        return taskScheduler;
    }
}
